home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 301-325 / 306 / rexxplplot / rexxsrc / rexxplplot.c < prev   
C/C++ Source or Header  |  1995-03-14  |  27KB  |  1,117 lines

  1. /* RexxPlPlot V0.2 - an ARexx front-end to PlPlot
  2.  *                 - written by Glenn M. Lewis - Caltech - 9/12/89
  3.  *                 - based on code by Tomas Rokicki of Radical Eye Software
  4.  */
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include "minrexx.h"
  8.  
  9. #define MAX(m,n) ((m)>(n)?(m):(n))
  10.  
  11. /* These are the functions we want to patch into */
  12. void pladv(), plbeg(), plbin(), plbox(), plbox3(), plclr(),
  13.     plcol(), plcont(), plend(), plenv(), plerrx(), plerry(),
  14.     plfont(), plgra(), plgrid3(), plgspa(),
  15.     plhist(), pljoin(), pllab(), plline(), plmtex(),
  16.     plot3d(), plpoin(), plptex(),
  17.     plschr(), plside3(), plsmaj(), plsmin(), plssym(), plstar(),
  18.     plstyl(), plsvpa(), plsym(), pltext(), plthicken(),
  19.     plvpor(), plvsta(), plw3d(), plwind(), xform(), set_transformation();
  20. void *malloc(), disp();
  21. double atof();
  22. int get_next_int();
  23. float get_next_float();
  24. char *get_char_pointer(), *parse_arg();
  25. void get_float_array(), get_2D_float_array(), get_int_array(),
  26.     write_next_float();
  27.  
  28. /* Static Variables */
  29. static int still_going;                /* Flag to shut down RexxPlPlot */
  30. static int parsed, quoted;            /* Flag to represent parsing success */
  31. static int return_result;            /* Flag whether function returns result */
  32. static char return_string[256];        /* Actual return result string */
  33. float tr[6] = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 };
  34.  
  35. /* Here are all of the patching rountines */
  36.  
  37. void Rpladv(msg, s)
  38. struct RexxMsg *msg;
  39. char *s;
  40. {
  41.     int sub;
  42.     sub = get_next_int(msg, &s);
  43. #ifdef DEBUG
  44.     printf("pladv(%d);\n", sub);
  45. #endif
  46.     if (parsed) pladv(sub);
  47. }
  48.  
  49. void Rplbeg(msg, s)
  50. struct RexxMsg *msg;
  51. char *s;
  52. {
  53.     int dev, nx, ny;
  54.     dev = get_next_int(msg, &s);
  55.     nx  = get_next_int(msg, &s);
  56.     ny  = get_next_int(msg, &s);
  57. #ifdef DEBUG
  58.     printf("plbeg(%d,%d,%d);\n", dev,nx,ny);
  59. #endif
  60.     if (parsed) plbeg(dev, nx, ny);
  61. }
  62.  
  63. void out_of_mem() ; /* forward declare this routine */
  64.  
  65. void Rplbin(msg, s)
  66. struct RexxMsg *msg;
  67. char *s;
  68. {
  69.     int nbin, cen;
  70.     float *x=0, *y=0;
  71.     nbin = get_next_int(msg, &s);
  72.     if (!parsed) return;
  73.     if (nbin) {
  74.         if (!(x = (float *) malloc(2*nbin*sizeof(float)))) out_of_mem();
  75.         y = &x[nbin];
  76.         get_float_array(msg, &s, x, nbin);
  77.         get_float_array(msg, &s, y, nbin);
  78.         cen = get_next_int(msg, &s);
  79. #ifdef DEBUG
  80.     printf("plbin(%d,%08x,%08x,%d);\n", nbin, x, y, cen);
  81. #endif
  82.     }
  83.     if (parsed) plbin(nbin, x, y, cen);
  84.     if (nbin) free((void *) x);
  85. }
  86.  
  87. void Rplbox(msg, s)
  88. struct RexxMsg *msg;
  89. char *s;
  90. {
  91.     char *xopt, *yopt;
  92.     float xtick, ytick;
  93.     int nxsub, nysub;
  94.     xopt  = get_char_pointer(msg, &s);
  95.     xtick = get_next_float(msg, &s);
  96.     nxsub = get_next_int(msg, &s);
  97.     yopt  = get_char_pointer(msg, &s);
  98.     ytick = get_next_float(msg, &s);
  99.     nysub = get_next_int(msg, &s);
  100. #ifdef DEBUG
  101.     printf("plbox('%s',%0.4f,%d,'%s',%0.4f,%d);\n",
  102.         xopt, xtick, nxsub, yopt, ytick, nysub);
  103. #endif
  104.     if (parsed) plbox(xopt, xtick, nxsub, yopt, ytick, nysub);
  105. }
  106.  
  107. void Rplbox3(msg, s)
  108. struct RexxMsg *msg;
  109. char *s;
  110. {
  111.     char *xopt, *xlabel, *yopt, *ylabel, *zopt, *zlabel;
  112.     float xtick, ytick, ztick;
  113.     int nxsub, nysub, nzsub;
  114.     xopt   = get_char_pointer(msg, &s);
  115.     xlabel = get_char_pointer(msg, &s);
  116.     xtick  = get_next_float(msg, &s);
  117.     nxsub  = get_next_int(msg, &s);
  118.     yopt   = get_char_pointer(msg, &s);
  119.     ylabel = get_char_pointer(msg, &s);
  120.     ytick  = get_next_float(msg, &s);
  121.     nysub  = get_next_int(msg, &s);
  122.     zopt   = get_char_pointer(msg, &s);
  123.     zlabel = get_char_pointer(msg, &s);
  124.     ztick  = get_next_float(msg, &s);
  125.     nzsub  = get_next_int(msg, &s);
  126. #ifdef DEBUG
  127.     printf("plbox3('%s','%s',%0.4f,%d,'%s','%s',%0.4f,%d,'%s','%s',%0.4f,%d);\n",
  128.         xopt,xlabel,xtick,nxsub,yopt,ylabel,ytick,nysub,zopt,zlabel,ztick,nzsub);
  129. #endif
  130.     if (parsed) plbox3(xopt,xlabel,xtick,nxsub,yopt,ylabel,ytick,nysub,zopt,zlabel,ztick,nzsub);
  131. }
  132.  
  133. void Rplclr(msg, s)
  134. struct RexxMsg *msg;
  135. char *s;
  136. {
  137. #ifdef DEBUG
  138.     printf("plclr();\n");
  139. #endif
  140.     plclr();
  141. }
  142.  
  143. void Rplcol(msg, s)
  144. struct RexxMsg *msg;
  145. char *s;
  146. {
  147.     int color;
  148.     color = get_next_int(msg, &s);
  149. #ifdef DEBUG
  150.     printf("plcol(%d);\n", color);
  151. #endif
  152.     if (parsed) plcol(color);
  153. }
  154.  
  155. void Rplcont(msg, s)
  156. struct RexxMsg *msg;
  157. char *s;
  158. {
  159.     float *z, *clevel;
  160.     int nx, ny, kx, lx, ky, ly, nlevel;
  161.     char *tmp_s = &return_string[0];
  162.     strcpy(tmp_s, s);    /* Save 'z' variable name */
  163.     parse_arg(&s);
  164.     nx = get_next_int(msg, &s);
  165.     ny = get_next_int(msg, &s);
  166.     if (nx==0 || ny==0) { parsed = 0; return; }
  167.     kx = get_next_int(msg, &s);
  168.     lx = get_next_int(msg, &s);
  169.     ky = get_next_int(msg, &s);
  170.     ly = get_next_int(msg, &s);
  171.     if (!parsed) return;
  172.     if (!(z = (float *) malloc(nx*ny*sizeof(float)))) out_of_mem();
  173.     get_2D_float_array(msg, &tmp_s, z, nx, ny);    /* Use original name */
  174.     tmp_s = &return_string[0];
  175.     strcpy(tmp_s, s);    /* Save 'clevel' variable name */
  176.     parse_arg(&s);
  177.     nlevel = get_next_int(msg, &s);
  178.     if (!nlevel) { parsed = 0; return; }
  179.     if (!(clevel = (float *) malloc(nlevel*sizeof(float)))) out_of_mem();
  180.     if (!parsed) { free((void *)z); return; }
  181.     get_float_array(msg, &tmp_s, clevel, nlevel);
  182. #ifdef DEBUG
  183.     printf("plcont(%08x,%d,%d,%d,%d,%d,%d,%08x,%d,%08x);\n",
  184.         z,nx,ny,kx,lx,ky,ly,clevel,nlevel,&xform);
  185. #endif
  186.     if (parsed)
  187.         plcont(z,nx,ny,kx,lx,ky,ly,clevel,nlevel,&xform);
  188.     free((void *) z);
  189. }
  190.  
  191. void Rplend(msg, s)
  192. struct RexxMsg *msg;
  193. char *s;
  194. {
  195.     still_going = 0;    /* This function stops PlPlot */
  196. #ifdef DEBUG
  197.     printf("plend();\n");
  198. #endif
  199.     plend();
  200. }
  201.  
  202. void Rplenv(msg, s)
  203. struct RexxMsg *msg;
  204. char *s;
  205. {
  206.     float xmin, xmax, ymin, ymax;
  207.     int just, axis;
  208.     xmin = get_next_float(msg, &s);
  209.     xmax = get_next_float(msg, &s);
  210.     ymin = get_next_float(msg, &s);
  211.     ymax = get_next_float(msg, &s);
  212.     just = get_next_int(msg, &s);
  213.     axis = get_next_int(msg, &s);
  214. #ifdef DEBUG
  215.     printf("plenv(%0.4f,%0.4f,%0.4f,%0.4f,%d,%d);\n",
  216.         xmin,xmax,ymin,ymax,just,axis);
  217. #endif
  218.     if (parsed) plenv(xmin,xmax,ymin,ymax,just,axis);
  219. }
  220.  
  221. void Rplerrx(msg, s)
  222. struct RexxMsg *msg;
  223. char *s;
  224. {
  225.     int n;
  226.     float *xmin, *xmax, *y;
  227.     n = get_next_int(msg, &s);
  228.     if (n==0) parsed=0;
  229.     if (!parsed) return;
  230.     if (!(xmin = (float *) malloc(3*n*sizeof(float)))) out_of_mem();
  231.     xmax = &xmin[n];
  232.     y    = &xmax[n];
  233.     get_float_array(msg, &s, xmin, n);
  234.     get_float_array(msg, &s, xmax, n);
  235.     get_float_array(msg, &s, y   , n);
  236. #ifdef DEBUG
  237.     printf("plerrx(%d,%08x,%08x,%08x);\n",
  238.         n,xmin,xmax,y);
  239. #endif
  240.     if (parsed) plerrx(n,xmin,xmax,y);
  241.     free((void *) xmin);
  242. }
  243.  
  244. void Rplerry(msg, s)
  245. struct RexxMsg *msg;
  246. char *s;
  247. {
  248.     int n;
  249.     float *x, *ymin, *ymax;
  250.     n = get_next_int(msg, &s);
  251.     if (n==0) parsed=0;
  252.     if (!parsed) return;
  253.     if (!(x = (float *) malloc(3*n*sizeof(float)))) out_of_mem();
  254.     ymin = &x[n];
  255.     ymax = &ymin[n];
  256.     get_float_array(msg, &s, x   , n);
  257.     get_float_array(msg, &s, ymin, n);
  258.     get_float_array(msg, &s, ymax, n);
  259. #ifdef DEBUG
  260.     printf("plerry(%d,%08x,%08x,%08x);\n",
  261.         n,x,ymin,ymax);
  262. #endif
  263.     if (parsed) plerry(n,x,ymin,ymax);
  264.     free((void *) x);
  265. }
  266.  
  267. void Rplfont(msg, s)
  268. struct RexxMsg *msg;
  269. char *s;
  270. {
  271.     int font;
  272.     font = get_next_int(msg, &s);
  273. #ifdef DEBUG
  274.     printf("plfont(%d);\n", font);
  275. #endif
  276.     if (parsed) plfont(font);
  277. }
  278.  
  279. void Rplgra(msg, s)
  280. struct RexxMsg *msg;
  281. char *s;
  282. {
  283. #ifdef DEBUG
  284.     printf("plgra();\n");
  285. #endif
  286.     plgra();
  287. }
  288.  
  289. void Rplgrid3(msg, s)
  290. struct RexxMsg *msg;
  291. char *s;
  292. {
  293.     float ztick;
  294.     ztick = get_next_float(msg, &s);
  295. #ifdef DEBUG
  296.     printf("plgrid3(%0.4f);\n", ztick);
  297. #endif
  298.     if (parsed) plgrid3(ztick);
  299. }
  300.  
  301. void Rplgspa(msg, s)
  302. struct RexxMsg *msg;
  303. char *s;
  304. {
  305.     float xmin, xmax, ymin, ymax;
  306.     plgspa(&xmin, &xmax, &ymin, &ymax);
  307.     write_next_float(msg, &s, xmin);
  308.     write_next_float(msg, &s, xmax);
  309.     write_next_float(msg, &s, ymin);
  310.     write_next_float(msg, &s, ymax);
  311. #ifdef DEBUG
  312.     printf("plgspa(%0.4f,%0.4f,%0.4f,%0.4f);\n",
  313.         xmin,xmax,ymin,ymax);
  314. #endif
  315. }
  316.  
  317. void Rplhist(msg, s)
  318. struct RexxMsg *msg;
  319. char *s;
  320. {
  321.     int n, nbin, oldwin;
  322.     float *data, datmin, datmax;
  323.     n = get_next_int(msg, &s);
  324.     if (n==0) parsed=0;
  325.     if (!parsed) return;
  326.     if (!(data = (float *) malloc(n*sizeof(float)))) out_of_mem();
  327.     get_float_array(msg, &s, data, n);
  328.     datmin = get_next_float(msg, &s);
  329.     datmax = get_next_float(msg, &s);
  330.     nbin   = get_next_int(msg, &s);
  331.     oldwin = get_next_int(msg, &s);
  332. #ifdef DEBUG
  333.     printf("plhist(%d,%08x,%0.4f,%0.4f,%d,%d);\n",
  334.         n,data,datmin,datmax,nbin,oldwin);
  335. #endif
  336.     if (parsed) plhist(n,data,datmin,datmax,nbin,oldwin);
  337.     free((void *) data);
  338. }
  339.  
  340. void Rpliff(msg, s)
  341. struct RexxMsg *msg;
  342. char *s;
  343. {
  344.     int x1, y1, x2, y2 ;
  345.     char *name ;
  346.  
  347.     x1 = get_next_int(msg, &s);
  348.     y1 = get_next_int(msg, &s);
  349.     x2 = get_next_int(msg, &s);
  350.     y2 = get_next_int(msg, &s);
  351.     name = get_char_pointer(msg, &s) ;
  352. #ifdef DEBUG
  353.     printf("pliff(%d,%d,%d,%d,%s);\n",
  354.         x1, y1, x2, y2, name);
  355. #endif
  356.     if (parsed) pliff(x1, y1, x2, y2, name);
  357. }
  358.  
  359. void Rpljoin(msg, s)
  360. struct RexxMsg *msg;
  361. char *s;
  362. {
  363.     float x1, y1, x2, y2;
  364.     x1 = get_next_float(msg, &s);
  365.     y1 = get_next_float(msg, &s);
  366.     x2 = get_next_float(msg, &s);
  367.     y2 = get_next_float(msg, &s);
  368. #ifdef DEBUG
  369.     printf("pljoin(%0.4f,%0.4f,%0.4f,%0.4f);\n",
  370.         x1, y1, x2, y2);
  371. #endif
  372.     if (parsed) pljoin(x1, y1, x2, y2);
  373. }
  374.  
  375. void Rpllab(msg, s)
  376. struct RexxMsg *msg;
  377. char *s;
  378. {
  379.     char *xlabel, *ylabel, *tlabel;
  380.     xlabel = get_char_pointer(msg, &s);
  381.     ylabel = get_char_pointer(msg, &s);
  382.     tlabel = get_char_pointer(msg, &s);
  383. #ifdef DEBUG
  384.     printf("pllab('%s','%s','%s');\n",
  385.         xlabel, ylabel, tlabel);
  386. #endif
  387.     if (parsed) pllab(xlabel, ylabel, tlabel);
  388. }
  389.  
  390. void Rplline(msg, s)
  391. struct RexxMsg *msg;
  392. char *s;
  393. {
  394.     int n;
  395.     float *x, *y;
  396.     n = get_next_int(msg, &s);
  397.     if (n==0) parsed=0;
  398.     if (!parsed) return;
  399.     if (!(x = (float *) malloc(2*n*sizeof(float)))) out_of_mem();
  400.     y = &x[n];
  401.     get_float_array(msg, &s, x, n);
  402.     get_float_array(msg, &s, y, n);
  403. #ifdef DEBUG
  404.     printf("plline(%d,%08x,%08x);\n",
  405.         n, x, y);
  406. #endif
  407.     if (parsed) plline(n, x, y);
  408.     free((void *) x);
  409. }
  410.  
  411. void Rplmtex(msg, s)
  412. struct RexxMsg *msg;
  413. char *s;
  414. {
  415.     char *side, *text;
  416.     float disp, pos, just;
  417.     side = get_char_pointer(msg, &s);
  418.     disp = get_next_float(msg, &s);
  419.     pos  = get_next_float(msg, &s);
  420.     just = get_next_float(msg, &s);
  421.     text = get_char_pointer(msg, &s);
  422. #ifdef DEBUG
  423.     printf("plmtex('%s',%0.4f,%0.4f,%0.4f,'%s');\n",
  424.         side, disp, pos, just, text);
  425. #endif
  426.     if (parsed) plmtex(side, disp, pos, just, text);
  427. }
  428.  
  429. void Rplot3d(msg, s)
  430. struct RexxMsg *msg;
  431. char *s;
  432. {
  433.     float *x, *y, *z;
  434.     int *work, ly, nx, ny, opt;
  435.     char *tmp_s = &return_string[0];
  436.     strcpy(tmp_s, s);    /* Save array variable names */
  437.     parse_arg(&s); parse_arg(&s); parse_arg(&s);    /* Delete variable names */
  438.     parse_arg(&s);        /* Get rid of 'WORK' argument */
  439.     ly  = get_next_int(msg, &s);
  440.     nx  = get_next_int(msg, &s);
  441.     ny  = get_next_int(msg, &s);
  442.     opt = get_next_int(msg, &s);
  443.     if (nx==0 || ny==0) parsed=0;
  444.     if (!parsed) return;
  445.     if (!(x = (float *) malloc((nx+1)*(ny+1)*sizeof(float)))) out_of_mem();
  446.     y = &x[nx];
  447.     z = &y[ny];
  448.     if (!(work = (int *) malloc(4*MAX(nx,ny)*sizeof(int)))) out_of_mem();
  449.     get_float_array(msg, &tmp_s, x, nx);
  450.     get_float_array(msg, &tmp_s, y, ny);
  451.     get_2D_float_array(msg, &tmp_s, z, nx, ly);
  452. #ifdef DEBUG
  453.     printf("plot3d(%08x,%08x,%08x,%08x,%d,%d,%d,%d);\n",
  454.         x,y,z,work,ly,nx,ny,opt);
  455. #endif
  456.     if (parsed) plot3d(x,y,z,work,ly,nx,ny,opt);
  457.     free((void *) work);
  458.     free((void *) x);
  459. }
  460.  
  461. void Rplpoin(msg, s)
  462. struct RexxMsg *msg;
  463. char *s;
  464. {
  465.     int n, code;
  466.     float *x, *y;
  467.     n = get_next_int(msg, &s);
  468.     if (n==0) parsed=0;
  469.     if (!parsed) return;
  470.     if (!(x = (float *) malloc(2*n*sizeof(float)))) out_of_mem();
  471.     y = &x[n];
  472.     get_float_array(msg, &s, x, n);
  473.     get_float_array(msg, &s, y, n);
  474.     if (!parsed) { free((void *) x); return; }
  475.     code = get_next_int(msg, &s);
  476. #ifdef DEBUG
  477.     printf("plpoin(%d,%08x,%08x,%d);\n",
  478.         n,x,y,code);
  479. #endif
  480.     if (parsed) plpoin(n,x,y,code);
  481.     free((void *) x);
  482. }
  483.  
  484. void Rplptex(msg, s)
  485. struct RexxMsg *msg;
  486. char *s;
  487. {
  488.     float x, y, dx, dy, just;
  489.     char *text;
  490.     x    = get_next_float(msg, &s);
  491.     y    = get_next_float(msg, &s);
  492.     dx   = get_next_float(msg, &s);
  493.     dy   = get_next_float(msg, &s);
  494.     just = get_next_float(msg, &s);
  495.     text = get_char_pointer(msg, &s);
  496. #ifdef DEBUG
  497.     printf("plptex(%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,'%s');\n",
  498.         x,y,dx,dy,just,text);
  499. #endif
  500.     if (parsed) plptex(x,y,dx,dy,just,text);
  501. }
  502.  
  503. void Rplschr(msg, s)
  504. struct RexxMsg *msg;
  505. char *s;
  506. {
  507.     float def, scale;
  508.     def   = get_next_float(msg, &s);
  509.     scale = get_next_float(msg, &s);
  510. #ifdef DEBUG
  511.     printf("plschr(%0.4f,%0.4f);\n",def, scale);
  512. #endif
  513.     if (parsed) plschr(def, scale);
  514. }
  515.  
  516. void Rplside3(msg, s)
  517. struct RexxMsg *msg;
  518. char *s;
  519. {
  520.     float *x, *y, *z;
  521.     int ly, nx, ny, opt;
  522.     char *tmp_s = &return_string[0];
  523.     strcpy(tmp_s, s);    /* Save array variable names */
  524.     parse_arg(&s); parse_arg(&s); parse_arg(&s);    /* Delete variable names */
  525.     ly  = get_next_int(msg, &s);
  526.     nx  = get_next_int(msg, &s);
  527.     ny  = get_next_int(msg, &s);
  528.     opt = get_next_int(msg, &s);
  529.     if (nx==0 || ny==0) parsed=0;
  530.     if (!parsed) return;
  531.     if (!(x = (float *) malloc((nx+1)*(ny+1)*sizeof(float)))) out_of_mem();
  532.     y = &x[nx];
  533.     z = &y[ny];
  534.     get_float_array(msg, &tmp_s, x, nx);
  535.     get_float_array(msg, &tmp_s, y, ny);
  536.     get_2D_float_array(msg, &tmp_s, z, nx, ly);
  537. #ifdef DEBUG
  538.     printf("plside3(%08x,%08x,%08x,%d,%d,%d,%d);\n",
  539.         x,y,z,ly,nx,ny,opt);
  540. #endif
  541.     if (parsed) plside3(x,y,z,ly,nx,ny,opt);
  542.     free((void *) x);
  543. }
  544.  
  545. void Rplsmaj(msg, s)
  546. struct RexxMsg *msg;
  547. char *s;
  548. {
  549.     float def, scale;
  550.     def   = get_next_float(msg, &s);
  551.     scale = get_next_float(msg, &s);
  552. #ifdef DEBUG
  553.     printf("plsmaj(%0.4f,%0.4f);\n",def, scale);
  554. #endif
  555.     if (parsed) plsmaj(def, scale);
  556. }
  557.  
  558. void Rplsmin(msg, s)
  559. struct RexxMsg *msg;
  560. char *s;
  561. {
  562.     float def, scale;
  563.     def   = get_next_float(msg, &s);
  564.     scale = get_next_float(msg, &s);
  565. #ifdef DEBUG
  566.     printf("plsmin(%0.4f,%0.4f);\n",def, scale);
  567. #endif
  568.     if (parsed) plsmin(def, scale);
  569. }
  570.  
  571. void Rplssym(msg, s)
  572. struct RexxMsg *msg;
  573. char *s;
  574. {
  575.     float def, scale;
  576.     def   = get_next_float(msg, &s);
  577.     scale = get_next_float(msg, &s);
  578. #ifdef DEBUG
  579.     printf("plssym(%0.4f,%0.4f);\n",def, scale);
  580. #endif
  581.     if (parsed) plssym(def, scale);
  582. }
  583.  
  584. void Rplstar(msg, s)
  585. struct RexxMsg *msg;
  586. char *s;
  587. {
  588.     int nx, ny;
  589.     nx = get_next_int(msg, &s);
  590.     ny = get_next_int(msg, &s);
  591. #ifdef DEBUG
  592.     printf("plstar(%d,%d);\n",nx,ny);
  593. #endif
  594.     if (parsed) plstar(nx, ny);
  595. }
  596.  
  597. void Rplstyl(msg, s)
  598. struct RexxMsg *msg;
  599. char *s;
  600. {
  601.     int nels, *mark=0, *space=0;
  602.     nels = get_next_int(msg, &s);
  603.     if (!parsed) return;
  604.     if (nels) {
  605.         if (!(mark = (int *) malloc(2*nels*sizeof(int)))) out_of_mem();
  606.         space = &mark[nels];
  607.         get_int_array(msg, &s,  mark, nels);
  608.         get_int_array(msg, &s, space, nels);
  609. #ifdef DEBUG
  610.     printf("plstyl(%d,%08x,%08x);\n",
  611.         nels, mark, space);
  612. #endif
  613.     }
  614.     if (parsed) plstyl(nels, mark, space);
  615.     if (nels) {
  616.         free((void *) mark );
  617.         free((void *) space);
  618.     }
  619. }
  620.  
  621. void Rplsvpa(msg, s)
  622. struct RexxMsg *msg;
  623. char *s;
  624. {
  625.     float xmin, xmax, ymin, ymax;
  626.     xmin = get_next_float(msg, &s);
  627.     xmax = get_next_float(msg, &s);
  628.     ymin = get_next_float(msg, &s);
  629.     ymax = get_next_float(msg, &s);
  630. #ifdef DEBUG
  631.     printf("plsvpa(%0.4f,%0.4f,%0.4f,%0.4f);\n",xmin,xmax,ymin,ymax);
  632. #endif
  633.     if (parsed) plsvpa(xmin,xmax,ymin,ymax);
  634. }
  635.  
  636. void Rplsym(msg, s)
  637. struct RexxMsg *msg;
  638. char *s;
  639. {
  640.     int n, code;
  641.     float *x, *y;
  642.     n = get_next_int(msg, &s);
  643.     if (n==0) parsed=0;
  644.     if (!parsed) return;
  645.     if (!(x = (float *) malloc(2*n*sizeof(float)))) out_of_mem();
  646.     y = &x[n];
  647.     get_float_array(msg, &s, x, n);
  648.     get_float_array(msg, &s, y, n);
  649.     code = get_next_int(msg, &s);
  650. #ifdef DEBUG
  651.     printf("plsym(%d,%08x,%08x,%d);\n",n,x,y,code);
  652. #endif
  653.     if (parsed) plsym(n,x,y,code);
  654.     free((void *) x);
  655. }
  656.  
  657. void Rpltext(msg, s)
  658. struct RexxMsg *msg;
  659. char *s;
  660. {
  661. #ifdef DEBUG
  662.     printf("pltext();\n");
  663. #endif
  664.     pltext();
  665. }
  666.  
  667.  
  668. void Rplthicken(msg, s)
  669. struct RexxMsg *msg;
  670. char *s;
  671. {
  672. #ifdef DEBUG
  673.     printf("plthicken();\n");
  674. #endif
  675.     plthicken();
  676. }
  677.  
  678. void Rplvpor(msg, s)
  679. struct RexxMsg *msg;
  680. char *s;
  681. {
  682.     float xmin, xmax, ymin, ymax;
  683.     xmin = get_next_float(msg, &s);
  684.     xmax = get_next_float(msg, &s);
  685.     ymin = get_next_float(msg, &s);
  686.     ymax = get_next_float(msg, &s);
  687. #ifdef DEBUG
  688.     printf("plvpor(%0.4f,%0.4f,%0.4f,%0.4f);\n",xmin,xmax,ymin,ymax);
  689. #endif
  690.     if (parsed) plvpor(xmin,xmax,ymin,ymax);
  691. }
  692.  
  693. void Rplvsta(msg, s)
  694. struct RexxMsg *msg;
  695. char *s;
  696. {
  697. #ifdef DEBUG
  698.     printf("plvsta();\n");
  699. #endif
  700.     plvsta();
  701. }
  702.  
  703. void Rplw3d(msg, s)
  704. struct RexxMsg *msg;
  705. char *s;
  706. {
  707.     float basex, basey, height, xmin, xmax, ymin, ymax, zmin, zmax, alt, az;
  708.     basex  = get_next_float(msg, &s);
  709.     basey  = get_next_float(msg, &s);
  710.     height = get_next_float(msg, &s);
  711.     xmin   = get_next_float(msg, &s);
  712.     xmax   = get_next_float(msg, &s);
  713.     ymin   = get_next_float(msg, &s);
  714.     ymax   = get_next_float(msg, &s);
  715.     zmin   = get_next_float(msg, &s);
  716.     zmax   = get_next_float(msg, &s);
  717.     alt    = get_next_float(msg, &s);
  718.     az     = get_next_float(msg, &s);
  719. #ifdef DEBUG
  720. printf("plw3d(%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f);\n",
  721.     basex,basey,height,xmin,xmax,ymin,ymax,zmin,zmax,alt,az);
  722. #endif
  723.     if (parsed) plw3d(basex,basey,height,xmin,xmax,ymin,ymax,zmin,zmax,alt,az);
  724. }
  725.  
  726. void Rplwind(msg, s)
  727. struct RexxMsg *msg;
  728. char *s;
  729. {
  730.     float xmin, xmax, ymin, ymax;
  731.     xmin = get_next_float(msg, &s);
  732.     xmax = get_next_float(msg, &s);
  733.     ymin = get_next_float(msg, &s);
  734.     ymax = get_next_float(msg, &s);
  735. #ifdef DEBUG
  736.     printf("plwind(%0.4f,%0.4f,%0.4f,%0.4f);\n",xmin,xmax,ymin,ymax);
  737. #endif
  738.     if (parsed) plwind(xmin,xmax,ymin,ymax);
  739. }
  740.  
  741. void set_transformation(msg, s)
  742. struct RexxMsg *msg;
  743. char *s;
  744. {
  745. #ifdef DEBUG
  746.     printf("Before: tr[6] = {%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f}\n",
  747.         tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]);
  748. #endif
  749.     tr[0] = get_next_float(msg, &s);
  750.     tr[1] = get_next_float(msg, &s);
  751.     tr[2] = get_next_float(msg, &s);
  752.     tr[3] = get_next_float(msg, &s);
  753.     tr[4] = get_next_float(msg, &s);
  754.     tr[5] = get_next_float(msg, &s);
  755. #ifdef DEBUG
  756.     printf("After:  tr[6] = {%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f}\n",
  757.         tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]);
  758. #endif
  759. }
  760.  
  761. /*
  762.  *   Here is our command association list.  Note that in this case,
  763.  *   we are setting the userdata field to be a function to call.
  764.  *   Dispatch will still take place through disp(), so common head
  765.  *   and tail stuff can go there.
  766.  *
  767.  *   Commands are all lower case, so we match either upper or lower.
  768.  *   (This is a requirement of minrexx.)
  769.  */
  770. struct rexxCommandList rcl[] = {
  771.     { "pladv",        (APTR)&Rpladv    },
  772.     { "plbeg",        (APTR)&Rplbeg    },
  773.     { "plbin",        (APTR)&Rplbin    },
  774.     { "plbox3",        (APTR)&Rplbox3    },
  775.     { "plbox",        (APTR)&Rplbox    },
  776.     { "plclr",        (APTR)&Rplclr    },
  777.     { "plcol",        (APTR)&Rplcol    },
  778.     { "plcont",        (APTR)&Rplcont    },
  779.     { "plend",        (APTR)&Rplend    },
  780.     { "plenv",        (APTR)&Rplenv    },
  781.     { "plerrx",        (APTR)&Rplerrx    },
  782.     { "plerry",        (APTR)&Rplerry    },
  783.     { "plfont",        (APTR)&Rplfont    },
  784.     { "plgra",        (APTR)&Rplgra    },
  785.     { "plgrid3",    (APTR)&Rplgrid3    },
  786.     { "plgspa",        (APTR)&Rplgspa    },
  787.     { "pliff",        (APTR)&Rpliff    },
  788.     { "plhist",        (APTR)&Rplhist    },
  789.     { "pljoin",        (APTR)&Rpljoin    },
  790.     { "pllab",        (APTR)&Rpllab    },
  791.     { "plline",        (APTR)&Rplline    },
  792.     { "plmtex",        (APTR)&Rplmtex    },
  793.     { "plot3d",        (APTR)&Rplot3d    },
  794.     { "plpoin",        (APTR)&Rplpoin    },
  795.     { "plptex",        (APTR)&Rplptex    },
  796.     { "plschr",        (APTR)&Rplschr    },
  797.     { "plside3",    (APTR)&Rplside3    },
  798.     { "plsmaj",        (APTR)&Rplsmaj    },
  799.     { "plsmin",        (APTR)&Rplsmin    },
  800.     { "plssym",        (APTR)&Rplssym    },
  801.     { "plstar",        (APTR)&Rplstar    },
  802.     { "plstyl",        (APTR)&Rplstyl    },
  803.     { "plsvpa",        (APTR)&Rplsvpa    },
  804.     { "plsym",        (APTR)&Rplsym    },
  805.     { "pltext",        (APTR)&Rpltext    },
  806.     { "plthicken",        (APTR)&Rplthicken    },
  807.     { "plvpor",        (APTR)&Rplvpor    },
  808.     { "plvsta",        (APTR)&Rplvsta    },
  809.     { "plw3d",        (APTR)&Rplw3d    },
  810.     { "plwind",        (APTR)&Rplwind    },
  811.     { "plset_tr",    (APTR)&set_transformation    },
  812.     { NULL, NULL } } ;
  813.  
  814. /* Main rountine.  Open up Libraries, print message,
  815.  * detach from CLI (eventually), and wait for ARexx messages
  816.  */
  817.  
  818. main(argc, argv)
  819. int argc;
  820. char *argv[];
  821. {
  822.     long rexxbit ;
  823.  
  824.     /* Maybe we should do more safety initialization here !?!? */
  825.  
  826. #ifdef LATTICE
  827.     onexit(dnRexxPort) ;
  828. #endif
  829.     printf("This is RexxPlPlot V0.3 by Glenn M. Lewis built on PlPlot 1.1a\n") ;
  830.         printf("  by Tony Richardson with modifcations by Sam Paolucci.\n") ;
  831.         printf("  IFF, Preferences and minrexx support by Tomas Rokicki.\n") ;
  832.     rexxbit = upRexxPort("PlPlot", rcl, "plot", &disp) ;
  833.     if (argc > 1)
  834.         asyncRexxCmd(argv[1]) ;
  835.     else
  836.         printf("[waiting for ARexx to send me a command...]\n");
  837.     still_going = 1;
  838.     while (still_going) {        /* Main loop */
  839.         Wait(rexxbit);
  840.         dispRexxPort() ;
  841.     }
  842. /*
  843.  *   With Rexx, we need to bring the port down.  You might make this
  844.  *   part of exit() for programs that have multiple paths to exit.
  845.  */
  846.     dnRexxPort() ;
  847.     Exit(0);        /* Call the AmigaDOS routine to shut down */
  848. }
  849.  
  850. /*   Make sure that the string is copied before it is chopped up.  ARexx
  851.  *   doesn't like other programs tampering with its strings
  852.  */
  853. static char work_string[256];
  854.  
  855. /*
  856.  *   This is our main dispatch function.
  857.  *   If everything else was successful, we return a 0 to ARexx.
  858.  *   Otherwise, we return a failure of 20 to indicate that the arguments
  859.  *   were messed up.
  860.  */
  861. void disp(msg, dat, s)
  862. register struct RexxMsg *msg;
  863. register struct rexxCommandList *dat;
  864. char *s;
  865. {
  866.     parsed = 1;        /* Assume that everything went OK */
  867.     strcpy(work_string, s);
  868.     ((void (*)()) dat->userdata)(msg, work_string);
  869.  
  870.     if (!parsed)
  871.         replyRexxCmd(msg, 20L, 10L, NULL);                /* Fail */
  872.     else if (return_result)
  873.         replyRexxCmd(msg,  0L,  0L, return_string);        /* It worked */
  874.     else
  875.         replyRexxCmd(msg,  0L,  0L, NULL);                /* It worked */
  876. }
  877.  
  878. void
  879. out_of_mem()
  880. {
  881.     printf("Ooops.  Out of memory.  Sorry.  I died.\n");
  882.     still_going = 0;
  883.     plend();
  884.     Exit(0);
  885. }
  886.  
  887. /* We have to make our own exit so that when PlPlot exit()'s, we close ARexx */
  888.  
  889. #ifndef LATTICE
  890. void
  891. _exit()
  892. {
  893.     dnRexxPort();
  894.     Exit(0);        /* Call the AmigaDOS exit function */
  895. }
  896. #endif
  897.  
  898. void
  899. uppercase(s)
  900. register char *s;
  901. {
  902.     while (*s) {
  903.         if (islower(*s)) *s = toupper(*s);
  904.         s++;
  905.     }
  906. }
  907.  
  908. /* Here are all of the parsing routines to perform the conversion magic */
  909. char *parse_arg(s)
  910. char **s;
  911. {
  912.     register char *p, *p2;
  913.     char delimiter;
  914.  
  915.     quoted = 0;        /* Let routines know if it was a string */
  916.     p = *s;
  917.     while (*p && (isspace(*p) || *p=='(' || *p==',')) p++;    /* Pass junk */
  918.     p2 = p;
  919.     if (*p2 == '\"' || *p2 == '\'') {    /* This arg is enclosed in quotes */
  920.         quoted = 1;
  921.         delimiter = *p2++;
  922.         p++;                            /* Chop off first delimiter */
  923.         while (*p2 && *p2 != delimiter) p2++;    /* Find matching delimiter */
  924.         if (*p2) *p2++ = '\0';            /* Chop off final delimiter */
  925.         while (*p2 && (isspace(*p2) || *p2==')' || *p2==',')) p2++;
  926.         *s = p2;    /* Point to next argument */
  927.         return(p);
  928.     }
  929.     /* Argument was not enclosed in quotes.  Find any delimiter */
  930.     while (*p2 && !isspace(*p2) && *p2 != ',' && *p2 != ')') p2++;
  931.     if (*p2) *p2++ = '\0';        /* Chop off final delimiter */
  932.     *s = p2;
  933.     return(p);
  934. }
  935.  
  936. void check_for_stems(msg, s)        /* Replace variable stems with integer */
  937. struct RexxMsg *msg;
  938. char *s;
  939. {
  940.     char temp[256], *value;
  941.     register int i, j;
  942.     uppercase(s);
  943.     for (i=0; s[i]; )
  944.         if (s[i++] == '.') {
  945.             for (j=0; s[i+j] && s[i+j]!='.'; j++) ;
  946.             if (j) strncpy(temp, &s[i], j);
  947.             temp[j] = '\0';
  948.             GetRexxVar(msg, temp, &value);
  949.             if (!(*value)) { parsed = 0; return; }
  950.             /* Got the variable contents - make room in the string */
  951.             strcpy(temp, &s[i+j]);
  952.             /* Check that 'value' is an integer */
  953.             for (j=0; value[j]; j++)
  954.                 if (value[j] <= '0' || value[j] >= '9') { parsed=0; return; }
  955.             strcpy(&s[i], value);
  956.             strcpy(&s[i+j], temp);    /* Add contents onto end */
  957.             i += j;
  958.         }
  959. }
  960.  
  961. int get_next_int(msg, s)
  962. struct RexxMsg *msg;
  963. char **s;
  964. {
  965.     register char *p;
  966.     char *value;
  967.  
  968.     p = parse_arg(s);    /* Return pointer to argument, advance 's' past it */
  969.     if ((*p >= '0' && *p <= '9') || *p == '-' || *p == '+')
  970.         return(atoi(p));    /* It's a number */
  971.     check_for_stems(msg, p);
  972.     if (!parsed) return(0);
  973.     GetRexxVar(msg, p, &value);
  974.     if (!(*value)) { parsed = 0; return(0); }
  975.     return(atoi(value));
  976. }
  977.  
  978. float get_next_float(msg, s)
  979. struct RexxMsg *msg;
  980. char **s;
  981. {
  982.     register char *p;
  983.     char *value;
  984.  
  985.     p = parse_arg(s);    /* Return pointer to argument, advance 's' past it */
  986.     if ((*p >= '0' && *p <= '9') || *p == '-' || *p == '+')
  987.         return((float)atof(p));    /* It's a number */
  988.     check_for_stems(msg, p);
  989.     if (!parsed) return(0.0);
  990.     GetRexxVar(msg, p, &value);
  991.     if (!(*value)) { parsed = 0; return(0.0); }
  992.     return((float)atof(value));
  993. }
  994.  
  995. static char save_it_away[256];
  996.  
  997. char *get_char_pointer(msg, s)
  998. struct RexxMsg *msg;
  999. char **s;
  1000. {
  1001.     register char *p;
  1002.     char *value;
  1003.  
  1004.     p = parse_arg(s);    /* Return pointer to argument, advance 's' past it */
  1005.     if (quoted) return(p);        /* It's a quoted string... return it */
  1006.     strcpy(save_it_away, p);    /* Save it away for later */
  1007.     check_for_stems(msg, save_it_away);
  1008.     if (!parsed) { parsed=1; return(p); }    /* Not a stem - return as string */
  1009.     GetRexxVar(msg, save_it_away, &value);
  1010.     if (!(*value)) { return(p); }    /* Not a variable... return it */
  1011.     /* Yes, it was a variable.  Pass the pointer of its value: */
  1012.     return(value);
  1013. }
  1014.  
  1015. void get_float_array(msg, s, array, n)
  1016. struct RexxMsg *msg;
  1017. char **s;
  1018. float *array;
  1019. int n;
  1020. {
  1021.     register int i;
  1022.     register char *p;
  1023.     char *value;
  1024.  
  1025.     p = parse_arg(s);    /* Return pointer to argument, advance 's' past it */
  1026.     uppercase(p);
  1027.     /* If there is only one value, then there is no need for a stem */
  1028.     if (n==1) {
  1029.         GetRexxVar(msg, p, &value);
  1030.         if (*value) {
  1031.             array[0] = (float) atof(value);
  1032.             return;
  1033.         }
  1034.         /* If it got to this line, couldn't find the variable. Check stem. */
  1035.     }
  1036.     /* Start reading all of its values */
  1037.     for (i=0; i<n; i++) {
  1038.         sprintf(save_it_away, "%s.%d", p, i+1);    /* Generate the stem */
  1039.         GetRexxVar(msg, save_it_away, &value);
  1040.         if (!(*value)) { parsed = 0; return; }
  1041.         array[i] = (float) atof(value);
  1042.     }
  1043.     return;
  1044. }
  1045.  
  1046. void get_2D_float_array(msg, s, array, nx, ny)
  1047. struct RexxMsg *msg;
  1048. char **s;
  1049. float *array;
  1050. int nx, ny;
  1051. {
  1052.     register int i, j;
  1053.     register char *p;
  1054.     char *value;
  1055.  
  1056.     p = parse_arg(s);    /* Return pointer to argument, advance 's' past it */
  1057.     uppercase(p);
  1058.     /* Start reading all of its values */
  1059.     for (i=0; i<nx; i++) {
  1060.         for (j=0; j<ny; j++) {
  1061.             sprintf(save_it_away, "%s.%d.%d", p, i+1, j+1);    /* Generate the stem */
  1062.             GetRexxVar(msg, save_it_away, &value);
  1063.             if (!(*value)) { parsed = 0; return; }
  1064.             array[i*ny+j] = (float) atof(value);
  1065.         }
  1066.     }
  1067.     return;
  1068. }
  1069.  
  1070. void get_int_array(msg, s, array, n)
  1071. struct RexxMsg *msg;
  1072. char **s;
  1073. int *array, n;
  1074. {
  1075.     register int i;
  1076.     register char *p;
  1077.     char *value;
  1078.  
  1079.     p = parse_arg(s);    /* Return pointer to argument, advance 's' past it */
  1080.     uppercase(p);
  1081.     /* If there is only one value, then there is no need for a stem */
  1082.     if (n==1) {
  1083.         GetRexxVar(msg, p, &value);
  1084.         if (*value) {
  1085.             array[0] = atoi(value);
  1086.             return;
  1087.         }
  1088.         /* If it got to this line, couldn't find the variable. Check stem. */
  1089.     }
  1090.     /* Start reading all of its values */
  1091.     for (i=0; i<n; i++) {
  1092.         sprintf(save_it_away, "%s.%d", p, i+1);    /* Generate the stem */
  1093.         GetRexxVar(msg, save_it_away, &value);
  1094.         if (!(*value)) { parsed = 0; return; }
  1095.         array[i] = atoi(value);
  1096.     }
  1097.     return;
  1098. }
  1099.  
  1100. void write_next_float(msg, s, val)
  1101. struct RexxMsg *msg;
  1102. char **s;
  1103. float val;
  1104. {
  1105.     register char *p;
  1106.  
  1107.     p = parse_arg(s);    /* Return pointer to argument, advance 's' past it */
  1108.     check_for_stems(msg, s);
  1109.     if (!parsed) return;
  1110.     /* Attempt to write the value */
  1111.     sprintf(save_it_away, "%0.8f", val);
  1112.     if (SetRexxVar(msg, p, save_it_away, strlen(save_it_away)))
  1113.         parsed = 0;        /* Wasn't able to write */
  1114.     return;
  1115. }
  1116.  
  1117.